package cleaner

import (
	"file-cleaner/internal/file_cleaner/file_info"
	v1log "github.com/ClessLi/component-base/pkg/log/v1"
	"path/filepath"
)

type CleanTaskInfo struct {
	sourceFileInfo *file_info.FileInfo
	targetFileInfo *file_info.FileInfo
}

func NewCleanTaskInfo(src, target *file_info.FileInfo) *CleanTaskInfo {
	return &CleanTaskInfo{
		sourceFileInfo: src,
		targetFileInfo: target,
	}
}

func (i CleanTaskInfo) SourceFileInfo() *file_info.FileInfo {
	return i.sourceFileInfo
}

func (i CleanTaskInfo) TargetFileInfo() *file_info.FileInfo {
	return i.targetFileInfo
}

func (i CleanTaskInfo) IsSamePath() bool {
	return filepath.Clean(i.sourceFileInfo.Path()) == filepath.Clean(i.targetFileInfo.Path())
}

func (i CleanTaskInfo) IsSameLinkFile() bool {
	err := i.targetFileInfo.RefreshStat()
	if err != nil {
		v1log.Warnf("Refresh target file(%v) stat failed, cased by: %v", i.targetFileInfo.Path(), err)
		return false
	}
	return i.sourceFileInfo.IsSameFile(i.targetFileInfo)
}

//func (i CleanTaskInfo) IsDifferentFilesystem() bool {
//	return !i.sourceFileInfo.IsSameFilesystem(i.targetFileInfo)
//}
